package club.laowang.chain.validation;

import club.laowang.chain.annotation.Max;
import club.laowang.chain.execption.ValidatorException;

public class MaxValidatorHandler implements ValidatorHandler{
    private Max max;

    public MaxValidatorHandler(Max max) {
        this.max = max;
    }

    @Override
    public void validator(Object value, ValidatorContext context) {
        if (value instanceof Integer) {
            Integer intValue = Integer.valueOf(value.toString());
            if (intValue > max.value()) {
                context.appendError("当前值为：" + intValue + "，大于max值：" + max.value());
            }
        }
    }
}
